package com.yeban.javase.day16.state.runnable;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/30
 *
 * 就绪状态 → 阻塞状态
 */
public class RunnableAndBlock {
    public static void main(String[] args) {
        Object lock = new Object();

        new Thread(() -> {
            synchronized (lock) {
                try {
                    Thread.sleep(2000); // 线程1持有锁2秒
                } catch (InterruptedException e) {}
            }
        }).start();

        new Thread(() -> {
            synchronized (lock) {  // 线程2试图获得锁
                System.out.println("线程2获取到锁");
            }
        }).start();
    }
}
